import wepy from 'wepy'

export default class extends wepy.mixin {
  methods = {
    onChange(e) {
      this.getOrderList(e.detail.name)
    } 
  }

  data = {
    active: 0,
    allList: '',
    waitList: '',
    doneList: ''
  }

  onLoad() {
    this.getOrderList(0)
  }

  async getOrderList(index) {
    const { data: res } = await wepy.get('/my/orders/all', {type: index + 1})

    if(res.meta.status !== 200) {
      return wepy.baseToast('请求数据失败')
    }

    if(index === 0) {
      // 全部
      this.allList = res.message.orders
    } else if(index === 1) {
      // 待付款
      this.waitList = res.message.orders
    } else if(index === 2) {
      // 已付款
      this.doneList = res.message.orders
    } else {
      return wepy.baseToast('数据请求失败')
    }

    this.$apply()
  }
}